<template>
    <div class="layout-route">
        <div class="card card-search">
            <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="120px">
                <!-- <el-form-item label="每月成本任务ID" prop="ordercheck_id">
                    <el-input v-model.trim="queryParams.ordercheck_id" placeholder="请输入每月成本任务ID" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item> -->
                <el-form-item label="物流渠道" prop="channels">
                    <el-input v-model.trim="queryParams.channels" placeholder="请输入物流渠道" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="月份" prop="date">
                    <el-date-picker type="monthrange" v-model="queryParams.date" start-placeholder="开始时间" end-placeholder="结束时间"></el-date-picker>
                </el-form-item>
                <el-form-item label=" ">
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </div>

        <div class="card">
            <el-row :gutter="10" class="mb8">
                <!-- <el-col :span="1.5">
                    <el-button type="warning" plain @click="downloadExcel">下载模板</el-button>
                </el-col> -->
                <el-col :span="1.5">
                    <upload-product @update="getList"></upload-product>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" :loading="download" :disabled="download" @click="handleExport">下载模板</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>

            <el-table v-loading="loading" :data="tableData" row-key="id" border script>
                <el-table-column label="ID" prop="id" min-width="80"></el-table-column>
                <el-table-column label="月份" prop="date" min-width="160"></el-table-column>
                <el-table-column label="物流单号" prop="transfer_number" min-width="160"></el-table-column>
                <el-table-column label="物流费" prop="freight" min-width="160"></el-table-column>
                <el-table-column label="状态" prop="status" min-width="160"></el-table-column>
                <el-table-column label="物流渠道" prop="tracking_company" min-width="320"></el-table-column>
                <el-table-column label="创建时间" prop="createtime" min-width="320"></el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList" />
        </div>
    </div>
</template>
<script>
import { queryOrderCheckLogisticsList, exportOrderCheckDispute } from '@/api/order'
import UploadProduct from '../components/UploadProduct.vue'
import { exportFile } from '@/utils/index'
import { parseTime } from '@/utils/quickadmin'
import { STATUS_LIST } from './constant'
export default {
    name: 'OrderCheckLogistics',
    components: {UploadProduct},
    data() {
        return {
            action: process.env.VUE_APP_BASE_API + '/order/OrderCheckLogistics/import',
            downloadUrl: '',
            // 遮罩层
            loading: true,
            download: false,
            // 选中数组
            ids: [],
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            tableData: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 状态数据字典

            dict: {
                STATUS_LIST,
            },
            pageInfo: {
                page: 1,
                limit: 10,
            },
            // 查询参数
            queryParams: {
                ordercheck_id: undefined,
                channels: undefined,
                date: [],
            },
        }
    },
    created() {
        this.getList()
    },
    methods: {
        toSupply(url) {
            window.open(url, '_blank')
        },
        handleClick() {
            this.getList()
        },
        downloadExcel() {
            window.open(this.downloadUrl, '_blank')
        },
        handleExport() {
            this.download = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
            }
            if (qyparams.date?.length == 2) {
                qyparams.date = [parseTime(qyparams.date[0], 'y-m'), parseTime(qyparams.date[1], 'y-m')]
            }
            exportOrderCheckDispute(qyparams)
                .then(res => {
                    console.log(res)
                    exportFile(res, () => {
                        this.download = false
                    })
                })
                .catch(err => {
                    console.log(err)
                    this.download = false
                })
        },
        showDetailDialog(row, type) {
            this.detailDialog.visible = true
            this.detailDialog.data = row
            this.detailDialog.type = type
        },
        showProductNewAuditDialog(row) {
            this.auditDialog.visible = true
            this.auditDialog.data = row
        },

        //列表
        getList() {
            this.loading = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
            }
            if (qyparams.date?.length == 2) {
                qyparams.date = [parseTime(qyparams.date[0], 'y-m'), parseTime(qyparams.date[1], 'y-m')]
            }
            queryOrderCheckLogisticsList(qyparams)
                .then(response => {
                    this.tableData = response.data.list
                    this.total = response.data.total
                })
                .finally(() => {
                    this.loading = false
                })
        },

        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },
    },
}
</script>
<style scoped>
.border-cell {
    padding: 0 !important;
}
.border-cell .cell {
    padding: 0 !important;
}
.border-cell-item {
    padding: 10px;
    border-bottom: 1px solid #dfe6ec;
}
.border-cell-item:last-child {
    border-bottom: 0;
}
.el-tabs--border-card {
    box-shadow: none;
    border-bottom: 0;
}

::v-deep .el-tabs .el-tabs__content {
    padding: 0;
    border-bottom: 0;
}
.table-wrap {
    padding: 15px;
    border-bottom: 1px solid #dfe4ed;
    border-left: 1px solid #dfe4ed;
    border-right: 1px solid #dfe4ed;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
}
</style>
